<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          :ellipsis="false"
          @select="handleSelect"
        >
          <el-menu-item index="0">
            <h3>"微商城"后台管理系统</h3>
          </el-menu-item>

          <el-sub-menu index="2">
            <template #title>
              <el-avatar
                :size="35"
                src="../../public/images/avatar-default.png"
              />
            </template>
            <el-menu-item index="2-1" @click="goTo('user')"
              >个人中心</el-menu-item
            >
            <el-menu-item index="2-2" @click="quit">退出登录</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-header>

      <el-container>
        <el-aside width="200px">
          <el-menu
            :default-active="route.path"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-menu-item index="/index/first" @click="goTo('first')">
              <el-icon><House /></el-icon>
              <span>首页</span>
            </el-menu-item>
            <el-menu-item index="/index/classify" @click="goTo('classify')">
              <el-icon><Coin /></el-icon>
              <span>分类管理</span>
            </el-menu-item>
            <el-menu-item index="/index/goods" @click="goTo('goods')">
              <el-icon><Coin /></el-icon>
              <span>商品管理</span>
            </el-menu-item>
            <el-menu-item index="/index/user" @click="goTo('user')">
              <el-icon><Setting /></el-icon>
              <span>个人中心</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { Setting, House, Coin } from '@element-plus/icons-vue';
import { useRouter } from 'vue-router';
import { useRoute } from 'vue-router';
import { useTokenStore } from '../store/tokenStore.js';

const router = useRouter();
const route = useRoute();
const tokenStore = useTokenStore();

const goTo = (to) => {
  router.push(to);
};

const quit = () => {
  tokenStore.removeToken();
  router.push('/');
};
</script>

<style scoped>
.el-menu--horizontal > .el-menu-item:nth-child(1) {
  margin-right: auto;
}

.el-menu--horizontal {
  height: 70px;
}

.el-container {
  margin-top: 10px;
}
</style>